<%@ page import="model.subjects.Enterprise, database.dao.EnterpriseDAO, model.Attribute, java.util.LinkedList" language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ettevõtte lisamine</title>
</head>

<a href='http://imbi.ld.ttu.ee/tomcat_webapp_logs/t103755_subjekt/log.txt'>loggid</a> ||<a href="LoginServlet?action=logout">Logi välja</a> 


<ul>
<a href='LoginServlet?action=login'>Otsing</a> || 
<a href='s?action=display_add_person'>Lisa Isikuid</a> || 
<a href='s?action=display_add_enterprise'>Lisa ettevõtteid</a> || 

</ul>
<body><h1>Ettevõtte lisamine</h1>
<form action='s?action=add_enterprise' method='post' >

<table  bgcolor='#C0C0C0' ><tr><td>
<!--  Üldised atribuudid -->
<tr><td>Ettevõtte nimi </td><td><input name="name" type="text"><br/></td></tr>
<tr><td>Ettevõtte täisnimi </td><td><input name="full_name" type="text"><br/></td></tr>

<br/>

<!-- Aadressi väljad -->
<tr><td></td><td>--------Aadressid------- <br/></td></tr></td></tr>
<tr><td>Riik </td><td><input name="country" type="text"><br/></td></tr>
<tr><td>Maakond </td><td><input name="county" type="text"><br/></td></tr>
<tr><td>Linn/küla </td><td><input name="town_village" type="text"><br/></td></tr>
<tr><td>Tänav, maja, korter </td><td><input name="street_address" type="text"><br/></td></tr>
<tr><td>Posti-indeks </td><td><input name="zipcode" type="number"><br/></td></tr>
<br/>

<%
//Isiku atribuudid
EnterpriseDAO personDao = new EnterpriseDAO();
LinkedList<Attribute> attributeNames = EnterpriseDAO.findAttributeNames();
for(Attribute a: attributeNames){
	int dataType = a.getDataType();
	System.out.println("Javas objektist võetud atribuudi tüüp on JSP-s " +dataType);
	out.println("<tr><td><label>"+a.getName()+ " </label></td><td><input name=\"" + a.getName() + "\" type=\"");
	if(dataType == 1){
		out.println("text");
	}else if(dataType == 2){
		out.println("number");
	}else{
		out.println("date");
	}
	out.println("\" ");
	if(a.isRequired()){
		out.println("required");
	}
	out.println(" ><br/></td></tr>"); //inputi lõpp
	
}
%>
<tr><td> </td><td><input type="submit" value="Lisa"></tr></td></table>
</form>
</body>
</html>